package goulu.bloggy.com.Helpers;

import java.security.MessageDigest;

public class LoginHelper 
{
	
	public static String Encrypt(String password)
	{
		MessageDigest md;
		String key = "";
		try
		{
			md = MessageDigest.getInstance("SHA-512");
			md.update(password.getBytes());
			byte[] mb = md.digest();
            String out = "";
            for (int i = 0; i < mb.length; i++) {
                byte temp = mb[i];
                String s = Integer.toHexString(new Byte(temp));
                while (s.length() < 2) {
                    s = "0" + s;
                }
                s = s.substring(s.length() - 2);
                out += s;
            }
            key = out;
            System.out.println(out.length());
            System.out.println("CRYPTO: " + out);
 
        } catch (Exception e) {
            e.printStackTrace();
        }
		return key;
	}
	
	public static boolean IsLoginCorrect(String username, String dbuser, String password, String dbpassword)
	{
		if(username.equals(dbuser) && password.equals(dbpassword))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
